package org.lt.cj.model.timer;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 
 * @author zgh
 */
public class TransferDataTimer {

    private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    //Transfer tran = new Transfer();

    public void executeTransferTimer() {

        Runnable task = new Runnable() {

            public void run() {
                //tran.transferGo();
                //插入操作代码

                System.out.println("*******转存数据完成。*******");
            }
        };
        scheduler.scheduleAtFixedRate(task, 0, 2, TimeUnit.SECONDS); // 延迟0秒，每隔2秒操作一次
    }

    public static void main(String[] args) {

        TransferDataTimer tt = new TransferDataTimer();
        tt.executeTransferTimer();
        try {
            Thread.sleep(10000);
        } catch (InterruptedException ex) {
        }
        // tt.wait(10000);
        tt.scheduler.shutdown();
        //tt.scheduler.shutdownNow();

    }
}
